package com.panda.mall.product.house.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panda.mall.common.mallProduct.dto.ProductHouseDto;
import com.panda.mall.common.mallProduct.entity.MallProductHouse;
import com.panda.mall.product.house.service.MallProductHouseService;
import com.panda.mall.product.house.mapper.MallProductHouseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author tucy123
* @description 针对表【mall_product_house(仓库信息表)】的数据库操作Service实现
* @createDate 2023-07-19 17:17:27
*/
@Service
public class MallProductHouseServiceImpl extends ServiceImpl<MallProductHouseMapper, MallProductHouse> implements MallProductHouseService{

    @Autowired
    MallProductHouseMapper mallProductHouseMapper;

    /**
     * Page<MallProductHouse>
     * @param productHouseDto
     * @return
     */
    @Override
    public Page<MallProductHouse> pageList(ProductHouseDto productHouseDto) {
        Page<MallProductHouse> page = new Page<>(productHouseDto.getPageNum(),productHouseDto.getPageSize());

        QueryWrapper<MallProductHouse> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .like(ObjectUtil.isNotEmpty(productHouseDto.getName()),MallProductHouse::getName,productHouseDto.getName())
                .like(ObjectUtil.isNotEmpty(productHouseDto.getAddress()),MallProductHouse::getAddress,productHouseDto.getAddress());

        return mallProductHouseMapper.selectPage(page,wrapper);
    }

    /**
     * 新增或保存
     * @param house
     * @return
     */
    @Override
    public Boolean saveOrUpdateHouse(MallProductHouse house) {
        return this.saveOrUpdate(house);
    }

    /**
     * 仓库详情
     * @param id
     * @return
     */
    @Override
    public MallProductHouse detail(Long id) {
        return this.getById(id);
    }

    /**
     * 删除仓库
     * @param ids
     * @return
     */
    @Override
    public Boolean delete(List<Long> ids) {
        int i = mallProductHouseMapper.deleteBatchIds(ids);
        return i != 0;
    }


}




